Hi,

I am using this page: admin/build/services/browse/node.save

This works:

{"type":"type_a","title":"this works ok","uid":3,"name":"rocksocker"}

This does not work and gives me a "Missing Required Arguments" message:

{"type":"type_a","title":"why doesnt this work","uid":3,"name":"rocksocker","field_custom_a": [{value:"test"}]}

And this generates a PHP error saying "Fatal error: Cannot use object of type stdClass as array in var/aegir/platforms/drupal6/sites/all/modules/cck/modules/text/text.module on line 439":

{"type":"type_a","title":"why doesnt this work","uid":3,"name":"rocksocker","field_custom_a": [{"value":"test"}]}

I believe this last example should work, according to examples I've found via Google.

Thank you

Comments

HermosilloSoKRok’s picture

I improved title to attract a response, as it's got to be something simple that will save me hours.

HermosilloSoKRok’s picture

Title: CCK Node » CCK field in node is throwing error. Need a quick reply on object formatting. Likely a 2 second fix for knowledgeable.
Category: support » bug
marcingy’s picture

Category: bug » support

This is a support request not a bug.

HermosilloSoKRok’s picture

You are quite sure it is not a bug? Then you must understand the solution can you please share it with me?

HermosilloSoKRok’s picture

Title: Bug in browser JSON test if using a CCK Field » CCK field in node is throwing error. Need a quick reply on object formatting. Likely a 2 second fix for knowledgeable.

I am sorry but I feel I need to disagree. At least you can tell me your logic. I created a node in drupal and using node.get I can see the format required which is the same that is reporting the error.

Also I found this page which suggests the similar thing with user.save http://drupal.org/node/822090 and http://drupal.org/node/679494

HermosilloSoKRok’s picture

Title: CCK field in node is throwing error. Need a quick reply on object formatting. Likely a 2 second fix for knowledgeable. » Bug in browser JSON test if using a CCK Field
Category: support » bug
HermosilloSoKRok’s picture

Title: CCK field in node is throwing error. Need a quick reply on object formatting. Likely a 2 second fix for knowledgeable. » CCK Field must have bug, all examples fail
Category: bug » support

ok I installed JSON Server because some other pages made me think the problem was the browser page. It took another few hours to figure out that because there seems to be a problem with documents and the code does not have any comments.

Only thanks to Google I have found some old pages that tell me I am doing the right thing:

cckfield = [{value:"this is the field text"}];

This throws errors on the JSON Server too so I am lead to decide that there is a problem within Services. I respect the person who says this is not a bug but he says this to me without saying any facts. For now I accept this is a support request but I have many doubts.

HermosilloSoKRok’s picture

The error is "Fatal error: Cannot use object of type stdClass as array in var/aegir/platforms/drupal6/sites/all/modules/cck/modules/text/text.module on line 439" so I read that Services requires two arrays. No error is given when I do that but no data is saved when I use [[{value:"test"}]]

Again node.get provides the structure I try to use [{value:"test"}]. This is the thing that causes errors in node.save.

This is a bug!!

matteblacke’s picture

Priority: Normal » Major

I am getting the same error for node.save using a similar string (below)

{"type":"rundata","uid":"1","title":"TITLE","body":"BODY","field_html_song_list":[{"value":"Song","format":"2"}]}

Cannot use object of type stdClass as array in modules/cck/modules/text/text.module on line 439

matteblacke’s picture

sorry, think i flicked the priority somehow.

voxpelli’s picture

Title: CCK Field must have bug, all examples fail » Change node argument type to array
Category: support » bug
Status: Active » Needs review
StatusFileSize
new554 bytes

This is indeed a bug. The node resource is defined as a struct - but since it calls drupal_execute() all values sent to it should be arrays. Both the browser in Services itself and the JSON server decodes JSON into objects instead of into associative arrays.

Some services does some internal type casting to get around this but none of that casting is recursive so specifying an associative array as the value of a cck field will fail - since the cck field's form handler expects an array.

I would suggest that we remove the type 'struct' from Services 3.x and disallows objects in arguments - all complex values that Services will need to handle can be expressed as arrays. Would there be any drawbacks for doing this?

The fix for Services 2.2 would be to change the type of the node.save argument to be 'array'. Patch is attached for that.

A patch has also been sent to the JSON server: #952344: Check if argument is struct or array and parse differently

voxpelli’s picture

Title: Change node argument type to array » Change node.save argument type to array

Status: Needs review » Needs work

The last submitted patch, 945788_change_nodesave_arg_to_array.patch, failed testing.

kylebrowning’s picture

Version: 6.x-2.2 » 6.x-2.x-dev
Status: Needs work » Needs review

Maybe you meant to set this to dev so the patch works?

kylebrowning’s picture

Status: Needs review » Needs work

The last submitted patch, 945788_change_nodesave_arg_to_array.patch, failed testing.

voxpelli’s picture

Um - how is it possible for such a small patch to fail? Can you try manually kylebrowning?

kylebrowning’s picture

Status: Needs work » Needs review
StatusFileSize
new971 bytes

Re-rolled patch.

kylebrowning’s picture

Status: Needs review » Reviewed & tested by the community
gdd’s picture

This is an API change, won't it break any existing installs?

marcingy’s picture

Can't comment on json but xmlrpc casts objects to arrays so xmlrpc has always been sending an array in effect anyway. So any xmlrpc code will still run as expected, other servers ???

voxpelli’s picture

@heyrocker: The function accepting the argument hasn't changed and the argument types aren't enforced in any way.

The fact that argument types aren't enforced is the reason how this can have slipped through. The values sent to drupal_execute() emulates $_POST and $_POST is an array - not a struct.

JSON server doesn't check the type and has parsed everything as a struct - in #952344: Check if argument is struct or array and parse differently it will be changed.

The only place I know that actually checks the argument type is Services' own browser - and as reported in this and other issues it currently fails on CCK-data.

So: If any API-change has occurred then that has already been made, but it forgot to change the argument type.

And since, as marcingy notes, many servers actually doesn't differentiate between struct and array I really think that we should remove struct in favour of array: #954964: Remove argument type 'struct' in favor of 'array'

voxpelli’s picture

Seems like also neither the REST Server or the JSONRPC Server checks whether an argument is a struct or an array - they both always parse JSON as arrays.

marcingy’s picture

Given voxpelli comments I'm happy to mark this rbtc as it sounds like no server is affected by the change as they already treat things as arrays anyway.

kylebrowning’s picture

Status: Reviewed & tested by the community » Fixed

This has been commited to 2.x-dev

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

mayur.pimple’s picture

Hi
This is poll type
-> how to update this node in services

[choice] => Array
(
[0] => Array
(
[chtext] => Football
[chvotes] => 2
[chorder] => 0
)
}

I want to update => [choice] [0] [chvotes] ;

voxpelli’s picture

@mayurpimple: Open new issues - don't hijack old closed issues

newnewuser’s picture

sub